package com.atwulidun.state20.raffle;

public class RaffleActivity {
    // state 表示活动当前的状态，是变化
    State state = null;
    // 奖品数量
    int count = 0;

    // 四个属性，表示四种状态
    State raffleNotPermittedState = new RaffleNotPermittedState(this);
    State rafflePermittedState = new RafflePermittedState(this);
    State dispenseState = new DispenseState(this);
    State dispensOutState = new DispenseOutState(this);

    // 构造器
    // 1. 初始化当前的状态为 rafflleNotPermittedState（即不能抽奖的状态）
    // 2. 初始化奖品的数量
    public RaffleActivity(int count) {
        this.state = raffleNotPermittedState;
        this.count = count;
    }

    // 扣分, 调用当前状态的deductMoney
    public void debuctMoney() {
        state.deductMoney();
    }

    // 抽奖
    public void raffle() {
        // 如果当前的状态是抽奖成功
        if (state.raffle()) {
            // 领取奖品
            state.dispensePrize();
        }
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    // 这里请大家注意，每领取一次奖品，count--
    public int getCount() {
        return count--;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public State getRaffleNotPermittedState() {
        return raffleNotPermittedState;
    }

    public void setRaffleNotPermittedState(State raffleNotPermittedState) {
        this.raffleNotPermittedState = raffleNotPermittedState;
    }

    public State getRafflePermittedState() {
        return rafflePermittedState;
    }

    public void setRafflePermittedState(State rafflePermittedState) {
        this.rafflePermittedState = rafflePermittedState;
    }

    public State getDispenseState() {
        return dispenseState;
    }

    public void setDispenseState(State dispenseState) {
        this.dispenseState = dispenseState;
    }

    public State getDispenseOutState() {
        return dispensOutState;
    }

    public void setDispenseOutState(State dispensOutState) {
        this.dispensOutState = dispensOutState;
    }
}
